<@pp.dropOutputFile/>
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign package = doc.groupid?replace(".", "/")> 
<#assign package = package + "/" + doc.artifactid?replace(".", "/")>
<#assign package = package + "/" + table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name="/main/java/" + package + "/service/" + fileName + "ServiceImpl.java"/>
package ${package?replace("/", ".")}.service;

import java.util.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
import blackstone.comm.ValidateUtil;
import blackstone.comm.Outcome;
import java.util.LinkedList;
import ${package?replace("/", ".")}.dao.${table.name?cap_first}Dao;
import ${package?replace("/", ".")}.domain.${fileName};

/**
 * Class ${fileName}ServiceImpl
 * ${fileName}Service interface implementation.
 * @author ${doc.author}
 * @version ${doc.version}, ${doc.date}
 */
public class ${fileName}ServiceImpl implements ${fileName}Service{
	private ${fileName}Dao ${fileName?uncap_first}Dao = null;
	private Log log = LogFactoryImpl.getLog(${fileName}ServiceImpl.class);
	
	public Outcome create(${fileName} newValue){
		Outcome res = null;

		res = ${fileName?uncap_first}Dao.create(newValue);
			
		return res;
	}

	public Outcome createBatch(List<${fileName}> items) {
		Outcome res = new Outcome(0);
		res.setMsg("import.success");
		List<${fileName} > ocs = new ArrayList<${fileName}>();
		if(null != items){
			for(${fileName} item : items){
				Outcome resItem = ${fileName?uncap_first}Dao.create(item);
				${fileName} newItem = resItem.getData();
				if(null != newItem){
					ocs.add(newItem);
				}
				if(!resItem.success()){
					res.setResult(-1);
				}
			}
		}
		res.setData(ocs);
		
		return res;
	}

	public Outcome get(String id) {
		Outcome res = null;
		res = ${fileName?uncap_first}Dao.get(id);
			
		return res;
	}
	
	public Outcome size(String id, Date start, Date end) {
		Outcome res = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("start", start);
		map.put("end", end);
		res = ${fileName?uncap_first}Dao.size(map);
		
		return res;
	}
	
	public Outcome getAll(){
		return getPage(1, 10000, null, null, null);
	}
	
	public Outcome getPage(Integer page, Integer rows, String id, Date start, Date end){
		Outcome res = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pageNumber", page);
		map.put("pageSize", rows);
		map.put("id", id);
		map.put("start", start);
		map.put("end", end);
		res = ${fileName?uncap_first}Dao.getPage(map);
		
		return res;
	}

	public Outcome getItems(List<String> items){
		Outcome res = null;
		res = ${fileName?uncap_first}Dao.getItems(items);
		
		return res;
	}
	
	public Outcome update(${fileName} newValue){
		Outcome res = null;
		res = ${fileName?uncap_first}Dao.update(newValue);
		
		return res;
	}
	
	public Outcome delete(String id){
		Outcome res = null;
		List<String> ids = new ArrayList<String>();
		ids.add(id);
		res = ${fileName?uncap_first}Dao.deleteItems(ids);
			
		return res;
	}

	public Outcome deleteItems(List<String> ids){
		Outcome res = null;
		res = ${fileName?uncap_first}Dao.deleteItems(ids);
		
		return res;
	}

	public Outcome deleteAll(){
		Outcome res = null;
		res = ${fileName?uncap_first}Dao.deleteAll();
		
		return res;
	}
	
	public void set${fileName}Dao(${fileName}Dao dao){
		${fileName?uncap_first}Dao = dao;
	}
}
</#list>